<template>
  <div>
    <div>
       法规环境法  organization.blog  规交付该减肥地方更好地发挥的is的故事的故事从V型从发鬼地方个的fghfghfghf {{ denglu.status }}
    </div>
    <button  @click="ok()">dddd</button>
    <button  @click="oak()">dddddddddd</button>
    <div v-if="repos" v-for="(index,key) in repos" :key="key">
      {{ index.site_name }}
    </div>
  </div>
</template>


<script>
import { reactive,toRefs,onMounted } from 'vue';
export default defineComponent({
  name: 'Indexe',
  head: {
    title: 'K.island'
  },
  async setup() {
    
    useMeta({
      meta: [
        { name: 'viewport', content: 'width=device-width, initial-scale=1, maximum-scale=1' }
      ],
      bodyAttrs: {
        class: 'test'
      }
    })

    const state = reactive({
      repos: [],
      denglu:{}
    });
    // const [{ data: organization }] = await Promise.all([
    //   useFetch(`https://api.github.com/orgs/nuxt`)
    // ])
    
    // console.log(organization)
    const config = useRuntimeConfig()

// 如果请求 独立写出的话  不能与 onMounted 同在否则  请求后面的onMounted无法执行 要么 onMounted后面的 请求无法执行  
// const { data:dddd,error } = await useAsyncData('ina', () => $fetch('http://crmebc.jishu.xhfiber.cn/api/pc/get_company_info',{method:'get'}))
//         // console.log(dddd.value.data)
//         // console.log(error.value)
//         if(error.value){
//           console.log("访问出错拉")
//         }else{
//           console.log(dddd.value.data)
//         }


  // const { msg:sss } = await $fetch('/api/login/mobile',{method:'post',body:{dfg:12121},baseURL:config.baseURL,headers:{'Authorization':'dfgdfg'}})
  //       console.log(sss)
const { data:sssssss } = await useFetch(`http://crmebc.jishu.xhfiber.cn/api/pc/get_company_info`,{transform:(data)=>{
        return data.data
      },headers:{'Authorization':'dfgdfg','Authori-zation':'sdfsdffs'}})
      state.repos = state.repos.concat(sssssss.value)

  const { msg:sss } = await $fetch('/api/login/mobile',{method:'post',body:{dfg:12121},baseURL:config.baseURL,headers:{'Authorization':'dfgdfg'}})
        console.log(sss,11111)

        await $fetch('/api/login/mobile',{method:'post',body:{dfg:12121},baseURL:config.baseURL,headers:{'Authorization':'dfgdfg'}}).then((data)=>{
          state.denglu = data
          console.log(state.denglu)
        }).catch(err=>{
          console.log(err)
        })


      // state.repos = state.repos.concat(sssssss)

// console.log(config.baseURL)
    // 不能与上面数据同存 上面数据比较有利于优化 数据展示
    // onMounted(async () => {
    //     await $fetch('/api/login/mobile',{method:'post',body:{dfg:12121},baseURL:config.baseURL,headers:{'Authorization':'dfgdfg'}}).then((data)=>{
    //       state.denglu = data
    //       console.log(state.denglu)
    //     }).catch(err=>{
    //       console.log(err)
    //     })
    //     console.log(state.denglu.status)
    //       const { msg:sss } = await $fetch('/api/login/mobile',{method:'post',body:{dfg:12121},baseURL:config.baseURL,headers:{'Authorization':'dfgdfg','Authori-zation':'sdfsdffs'}})
    //     console.log(sss)
        
    // })
    

    const ok = async () =>{
      const { data } = await useFetch(`http://crmebc.jishu.xhfiber.cn/api/pc/get_company_info`,{transform:(data)=>{
        return data.data
      },headers:{'Authorization':'dfgdfg','Authori-zation':'sdfsdffs'}})
      state.repos = state.repos.concat(data.value)
      console.log('fff',state.repos)
    }

    const oak =  async () => {
      const { data }  = await useAsyncData('indexa', () => $fetch('http://crmebc.jishu.xhfiber.cn/api/pc/get_company_info',{method:'get',params:{dfg:12121}}))
      console.log(data.value.data)
      state.repos.push(data.value.data)
    };

    return {
      ...toRefs(state),
      // organization,
      ok,
      oak
    }
  }
})
</script>




